Repository navigation
[Microsoft.Android.Sdk] Ship .NET 12 Android as NuGet library packs - #13769
Open
jonathanpeppers wants to merge 9 commits into
Open
jonathanpeppers wants to merge 9 commits into
jonathanpeppers wants to merge 9 commits into
Conversation
Context: https://gist.github.com/jonathanpeppers/3266a1498009182dd9df434e32e52734 As an intermediate step towards workload-free Android builds, .NET 12 projects get the Android build from the `Microsoft.Android` NuGet. The `android` workload stays, but it lists all of our packages as `"kind": "library"` packs (like dotnet/maui), so restore works offline. A future step deletes the workload and moves the remaining targets to dotnet/sdk. ### Packages * `Microsoft.Android`: one dependency group per `net12.0-android[API]`. It is a multi-targeted `Microsoft.Build.NoTargets` project, packed after the packages below. * `Microsoft.Android.net12.0`: MSBuild targets, tasks, analyzer, `buildTransitive/` props, and the native runtimes in `native/[runtime]/[rid]/`. NuGet does not know about runtime flavors, so the `_AndroidResolveRuntimePackageAssets` target adds these files. * `Microsoft.Android.net12.0.Ref.[API]`: `Mono.Android.dll` and `Java.Interop.dll`, as `ref/` and `runtimes/android/lib/` assets. * `Microsoft.Android.Tools.[Darwin|Linux|Windows]`: `tools/aapt2`. Each one sets `$(Aapt2ToolPath)` only on its own host OS. `SignList.xml` now matches `aapt2` by file name. These replace the `Microsoft.Android.Sdk.[OS]`, `Microsoft.Android.Ref.[API]`, and `Microsoft.Android.Runtime.*` packs, and the `FrameworkReference` items. ### Workload `WorkloadManifest.targets` only sets what restore needs, because restore does not import targets from packages: `$(TargetPlatformSupported)`, the default `$(TargetPlatformVersion)`, `$(RuntimeIdentifiers)`, and the properties that request the ILLink, Crossgen2, and NativeAOT packs. It also sets `$(MicrosoftAndroidPackageVersion)`. Without a `Microsoft.Android` `PackageReference`, the build fails with the new XA1052 error. net11.0-android projects still use the `Microsoft.Android.Sdk.net11` workload pack. Projects must add: ```xml <PackageReference Include="Microsoft.Android" Version="..." /> ``` The templates add it with the version of the templates. In this repository, `Directory.Build.targets` adds it with `$(MicrosoftAndroidPackageVersion)`. ### Local builds `ConfigureLocalWorkload` packs the library packs with `$(AndroidPackVersion)` into `bin/[Configuration]/dotnet/library-packs`, and removes the extracted copies from the NuGet cache. After editing `.targets` files, run it again. Test projects extract the packages from `library-packs`. ### Validation * `dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll` with focused filters: `DotNetNew`, `DotNetPublish`, `MauiTargetFramework` (net11.0 and net12.0), `BuildAfterUpgradingNuget`, `RuntimeLibraryFiltering`, `SdkPackageDoesNotContainCPlusPlusArchives`, trimmable typemap tests (CoreCLR and NativeAOT), `CheckIncludedAssemblies`, `CheckIncludedNativeLibraries`, `DotNetBuildLibrary`, `DotNetBuildBinding`, `ProjectDependencies`: all passed; skipped cases are unsupported configurations. * `dotnet-local.cmd test` for `Microsoft.Android.Build.Tasks.Tests` with `GenerateTrimmableTypeMap`: 64 passed. * Debug, Release, and NativeAOT template apps start on a Pixel 6 Pro. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* CodeBehindTests and MultiTfmTransitiveReference build projects
outside the repository, so add the Microsoft.Android PackageReference
in the tests (XA1052).
* InvalidR8ObfuscationModeIsValidatedOnlyForR8: restore, so the
package targets are imported (MSB4057).
* TestEnvironment: make extracted package files executable on Unix,
like NuGet does, so tools/aapt2 can run.
* DotNetInstallAndRunMinorAPILevels: net11.0 projects use
Microsoft.Android.Ref.[API], not the net12.0 packages.
* InstallWithoutSharedRuntime: Install with fast deployment only
builds the device ABI. The test did not check anything before, because
GetSupportedRuntimes returned nothing.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 25, 2026
net11.0 targeting-pack references have no NuGetPackageId metadata, so check the path of @(ReferencePath) instead. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…id-library-packs # Conflicts: # src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/in/Microsoft.Android.Sdk.BundledVersions.in.targets # tests/Mono.Android-Tests/Directory.Build.targets
…id-library-packs # Conflicts: # src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs # src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs # tests/MSBuildDeviceIntegration/Tests/InstallTests.cs
Restore does not import the Microsoft.Android package targets, so the
Mono workload saw $(RunAOTCompilation)=true and requested its AOT packs:
error NETSDK1147: To build this project, the following workloads must be installed: mobile-librarybuilder
Set $(RunAOTCompilation) to false during restore in WorkloadManifest.targets,
which is imported before the Mono workload's. The build still reports
XA1044, because the package targets read the project's value.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`dotnet run` evaluates the project before restore and reuses that evaluation for DeployToDevice, so on a project that was never restored it does not find the target from the Microsoft.Android NuGet and skips deployment: dotnet/sdk#57403 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run Xamarin.Android-PR |
|
No pipelines are associated with this pull request. |
The macOS job already builds all three Microsoft.Android.Tools packages. The Linux job built Microsoft.Android.Tools.Linux again from the same prebuilt Google aapt2, which gave two packages with the same id and version but different bytes. The Linux job now only builds and checks the SDK; the Linux signing job and the nuget-linux-* artifacts are removed. The Tools packages contain no pdbs, so do not create .symbols.nupkg files for them. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
133c6c84225df331167614d851afe0800f1625a0UnsupportedMonoAotPropertyFailsBuildpasses locally (6 of 6), and the net11.0 reference assertion passes locally.↑
dotnet restorethendotnet runinstalls the app and passes the environment variables on a Pixel 6 Pro.↑ The Tools packages pack locally without
.symbols.nupkgfiles; the changed pipeline YAML files parse.↓ CI has not run on this revision. The signing and MSI conversion changes run only in the official
Xamarin.Androidpipeline, so they are not verified.↓ Device tests were not run through the test runner locally.
↓
dotnet runbefore restore stays broken until dotnet/sdk#57403 is fixed.↓ The package rename affects downstream consumers (dotnet/maui darc, VS insertion).
Context: https://gist.github.com/jonathanpeppers/3266a1498009182dd9df434e32e52734
This is the first step towards building Android apps without a workload. .NET 12 projects get the Android build from the
Microsoft.AndroidNuGet package. Theandroidworkload stays for now, but it lists all of our packages as"kind": "library"packs, as dotnet/maui does, so restore works offline. Later, we can delete the workload and move the remaining targets to dotnet/sdk.Packages
Microsoft.Android: one dependency group pernet12.0-android[API]. It is a multi-targetedMicrosoft.Build.NoTargetsproject.Microsoft.Android.net12.0: MSBuild targets, tasks, analyzer, and the native runtimes innative/[runtime]/[rid]/. NuGet does not know about runtime flavors, so the_AndroidResolveRuntimePackageAssetstarget adds these files.Microsoft.Android.net12.0.Ref.[API]:Mono.Android.dllandJava.Interop.dll, asref/andruntimes/android/lib/assets.Microsoft.Android.Tools.[Darwin|Linux|Windows]:tools/aapt2. Each package sets$(Aapt2ToolPath)only on its own OS. These packages contain no pdbs, so they have no.symbols.nupkg.These replace the
Microsoft.Android.Sdk.[OS],Microsoft.Android.Ref.[API], andMicrosoft.Android.Runtime.*packs, and the implicitFrameworkReferenceitems.Workload
Restore does not import targets from packages, so
WorkloadManifest.targetssets only what restore needs:$(TargetPlatformSupported), the default$(TargetPlatformVersion),$(RuntimeIdentifiers), and the properties that request the ILLink, Crossgen2, and NativeAOT packs. It also sets$(MicrosoftAndroidPackageVersion). A project without aMicrosoft.AndroidPackageReferencefails with the new XA1052 error. net11.0-android projects still use theMicrosoft.Android.Sdk.net11workload pack.The templates add the
PackageReferencewith the version of the templates. In this repo,Directory.Build.targetsadds it.Local builds
ConfigureLocalWorkloadpacks the packages with$(AndroidPackVersion)intobin/[Configuration]/dotnet/library-packs, and removes old extracted copies from the NuGet cache. After you edit.targetsfiles, run it again.Restore
Restore, and the first evaluation of
dotnet run, do not import targets from packages:WorkloadManifest.targetssets$(RunAOTCompilation)tofalseduring restore. Otherwise the Mono workload requests its AOT packs and restore fails withNETSDK1147: ... mobile-librarybuilder, instead of the build reporting XA1044.dotnet runon a project that was never restored builds the app, but does not install it. The SDK evaluates the project before restore and reuses that evaluation forComputeAvailableDevicesandDeployToDevice: dotnet run skips ComputeAvailableDevices and DeployToDevice when they come from a NuGet package and the project is not restored sdk#57403. Templates restore when they create the project, sodotnet new androidfollowed bydotnet runworks.DotNetRunEnvironmentVariablesnow runsdotnet restorefirst.CI
aapt2comes from Google's prebuilt build-tools archives for all three OSes, so the macOS job builds all three Tools packages. Before, the Linux job also builtMicrosoft.Android.Tools.Linux, which gave two packages with the same id and version but different bytes. The Linux job now only builds and checks the SDK. Thenuget-linux-*artifacts and the Linux signing job are removed. The MSI conversion skips*Linux*packages, as it does for*Darwin*.Open questions
SignList.xmlnow matchesaapt2by file name. The internal Arcade signing already did this. I did not check thesign-artifactstemplate inazure-pipelines.yaml.Microsoft.Android.Sdk.Windowsthrough darc; it must change toMicrosoft.Android.WorkloadManifest.targets, so it is not localized.Validation
On Windows, with the local SDK:
dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dllwith filters forDotNetNew,DotNetPublish,MauiTargetFramework(net11.0 and net12.0),BuildAfterUpgradingNuget,RuntimeLibraryFiltering,SdkPackageDoesNotContainCPlusPlusArchives, trimmable typemap (CoreCLR and NativeAOT),CheckIncludedAssemblies,CheckIncludedNativeLibraries,DotNetBuildLibrary,DotNetBuildBinding, andProjectDependencies: all passed. Skipped cases are unsupported configurations.CodeBehindTests,MultiTfmTransitiveReference,InvalidR8ObfuscationModeIsValidatedOnlyForR8, andCompareAapt2AndManagedParserOutput: 34 passed.Microsoft.Android.Tools.projfor Darwin, Linux, and Windows: three.nupkgfiles, no.symbols.nupkg.DotNetNew,SuccessfulBuildFew,InvalidR8ObfuscationModeIsValidatedOnlyForR8,MultiTfmTransitiveReference,BuildAfterUpgradingNuget, andMauiTargetFramework: 36 passed, 2 skipped. Thetests/TrimmingTestscaseBooleanAndCharCallbacks.csbuilds.Xamarin.Android.Build.Tests.csprojandXamarin.Android.Build.Tasksbuild with 0 errors. I did not run tests again.dotnet-local.cmd test --test-modules bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter "Name~UnsupportedMonoAotPropertyFailsBuild": failed 2 of 6 before theRunAOTCompilationchange, 6 of 6 passed after it.dotnet new android --no-restore:dotnet run -e RUNENV_FOO=...without restore does not install the app (Invalid packageName); afterdotnet restore, it installs, starts, and logs the variable.Microsoft.Android.Build.Tasks.TestswithGenerateTrimmableTypeMap: 64 passed.I did not run the full test suites or
MSBuildDeviceIntegrationlocally. On Windows, its teardown runsadb kill-server, which would disconnect the devices shared with other work on this machine.